import logger from '../core/logger';
import apiInfo from './core/apiInfo';
import { clientBase } from './core/clientBase';
import nodeInfo from '../model/videos/nodeInfo';
import returnModel from '../model/common/returnModel';

export default class interactiveClient extends clientBase {
  private readonly aid: string;
  private readonly graphVersion: number;

  constructor(aid: string, graphVersion?: number) {
    super();
    this.aid = aid;
    this.graphVersion = graphVersion ? graphVersion : 467;
  }

  interactionEdgeInfo(nodeId: number = 0): Promise<returnModel<nodeInfo>> {
    var self = this;
    return new Promise((resolve) => {
      try {
        let info = new apiInfo("https://api.bilibili.com/x/stein/nodeinfo", `&aid=${this.aid}&delay=0&graph_version=${this.graphVersion}&node_id=${nodeId}`, null, true);
        this.client.getResult(info).then((res) => {
          var data: nodeInfo = res.data;
          resolve(self.buildSuccessResult<nodeInfo>(data));
        });
      } catch (e) {
        logger.error(e);
        resolve(self.buildExceptionResult<nodeInfo>(e));
      }
    });
  }
}